﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using PaperWorld.IService;
using PaperWorld.DTOAdapter;
using PaperWorld.DTO;
using PaperWorld.Web.Models;
using PaperWorld.Web.Models.Users;

namespace PaperWorld.Web.Controllers
{
    public class AccountController : ControllerBase
    {
        private IUserService service;

        public AccountController(IUserService service)
        {
            this.service = service;
        }

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginModel">用户登录模型</param>
        /// <returns>Json</returns>
        [HttpPost]
        public ActionResult Login(LoginModel loginModel)
        {
            var result = UserModelMapper.ToLoginResultModel(service.Login(UserModelMapper.ToUserLoginRequest(loginModel)));
            if (result.State)
            {
                //TODO: 
            }
            ViewBag.Result = result;
            return View();
        }
    }
}
